package top.zhangjianyong.blog.manage.controller;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.zhangjianyong.blog.params.file.UploadParam;
import top.zhangjianyong.blog.response.ApiResponse;
import top.zhangjianyong.blog.service.FileService;

/**
 * 文件Controller
 *
 * @author zhangjianyong
 * @since 2024/7/25 下午11:02
 */
@RequestMapping("/file")
@RestController
public class FileController {

    private final FileService fileService;

    public FileController(FileService fileService) {
        this.fileService = fileService;
    }

    @PostMapping("/upload")
    public ApiResponse upload(@Validated UploadParam param) {
        return fileService.upload(param);
    }

    @GetMapping("/{id}")
    public ApiResponse get(
        @PathVariable("id") Long id,
        HttpServletResponse response) {
        // 防盗链验证已由AntiHotlinkFilter统一处理
        return fileService.get(id, response);
    }
}
